/**
 * Copyright (c) 2014, 2017, Oracle and/or its affiliates.
 * The Universal Permissive License (UPL), Version 1.0
 */
"use strict";
define(["ojs/ojcore","jquery","ojs/ojdatasource-common","ojs/ojrowexpander"],function(a){a.Hh=function(g,b,c,d,e){a.p.jF(c);this.fd=g;this.pg=b;this.FN=c;this.sc=d;this.qa=e};o_("FlattenedTreeHeaderSet",a.Hh,a);a.Hh.prototype.getData=function(g,b){var c;a.p.assert(g<=this.pg&&g>=this.fd,"index out of bounds");a.p.assert(null==b||0==b,"level out of bounds");return null!=this.qa&&null!=this.sc?(c=this.sc.getData(g-this.fd+this.sc.getStart()),null!=c?c.get?c.get(this.qa):c[this.qa]:null):this.FN[g]};
a.b.g("FlattenedTreeHeaderSet.prototype.getData",{getData:a.Hh.prototype.getData});a.Hh.prototype.getMetadata=function(g,b){a.p.assert(g<=this.pg&&g>=this.fd,"index out of bounds");a.p.assert(null==b||0==b,"level out of bounds");return null!=this.qa&&null!=this.sc?this.sc.getMetadata(g-this.fd+this.sc.getStart()):{key:this.getData(g)}};a.b.g("FlattenedTreeHeaderSet.prototype.getMetadata",{getMetadata:a.Hh.prototype.getMetadata});a.Hh.prototype.getCount=function(){return null!=this.qa&&null!=this.sc?
Math.min(this.sc.getCount(),this.pg-this.fd):Math.max(0,this.pg-this.fd)};a.b.g("FlattenedTreeHeaderSet.prototype.getCount",{getCount:a.Hh.prototype.getCount});a.Hh.prototype.getLevelCount=function(){return 0<this.getCount()?1:0};a.b.g("FlattenedTreeHeaderSet.prototype.getLevelCount",{getLevelCount:a.Hh.prototype.getLevelCount});a.Hh.prototype.getExtent=function(g,b){a.p.assert(g<=this.pg&&g>=this.fd,"index out of bounds");a.p.assert(null==b||0==b,"level out of bounds");return{extent:1,more:{before:!1,
after:!1}}};a.b.g("FlattenedTreeHeaderSet.prototype.getExtent",{getExtent:a.Hh.prototype.getExtent});a.Hh.prototype.getDepth=function(g,b){a.p.assert(g<=this.pg&&g>=this.fd,"index out of bounds");a.p.assert(null==b||0==b,"level out of bounds");return 1};a.b.g("FlattenedTreeHeaderSet.prototype.getDepth",{getDepth:a.Hh.prototype.getDepth});a.ul=function(g,b,c,d,e,f){a.p.jF(f);this.Ea=g;this.ob=b;this.Mp=c;this.Uw=d;this.sc=e;this.Tf=f};o_("FlattenedTreeCellSet",a.ul,a);a.ul.prototype.getData=function(g){var b,
c,d,e;b=this.I8(g);if(null==b)return null;g=b[0];b=b[1];a.p.assert(g<this.sc.getStart()+this.sc.getCount()&&b<this.Tf.length);c=this.Tf[b];d=this.sc.getData(g);return null!=d?(g={},b=d.get?function(){return d.get(c)}:function(){return d[c]},e=d.set?function(a){return d.set(c,a)}:function(a){d[c]=a},Object.defineProperty(g,"data",{get:b,set:e}),g):null};a.b.g("FlattenedTreeCellSet.prototype.getData",{getData:a.ul.prototype.getData});a.ul.prototype.getMetadata=function(g){var b;b=this.I8(g);if(null==
b)return null;g=b[0];b=b[1];a.p.assert(g<this.sc.getStart()+this.sc.getCount()&&b<this.Tf.length);b=this.Tf[b];g=this.sc.getMetadata(g);g.keys={row:g.key,column:b};return g};a.b.g("FlattenedTreeCellSet.prototype.getMetadata",{getMetadata:a.ul.prototype.getMetadata});a.ul.prototype.I8=function(g){var b;a.p.mi(g);if(null==this.sc||0==this.sc.length)return null;b=g.row-this.Ea+this.sc.getStart();g=g.column;a.p.Uq(b,null);a.p.Uq(g,null);a.p.assert(0<=b&&0<=g);return[b,g]};a.ul.prototype.getStart=function(a){return"row"===
a?this.Ea:"column"===a?this.Mp:0};a.b.g("FlattenedTreeCellSet.prototype.getStart",{getStart:a.ul.prototype.getStart});a.ul.prototype.getCount=function(a){return"row"===a?Math.min(this.ob-this.Ea,this.sc.getCount()):"column"===a?this.Uw-this.Mp:0};a.b.g("FlattenedTreeCellSet.prototype.getCount",{getCount:a.ul.prototype.getCount});a.Ab=function(g,b){a.Ab.u.constructor.call(this,g,b)};o_("FlattenedTreeDataGridDataSource",a.Ab,a);a.b.sa(a.Ab,a.ua,"oj.FlattenedTreeDataGridDataSource");a.Ab.prototype.Init=
function(){a.Ab.u.Init.call(this);this.Tf=a.Ab.u.xF.call(this,"columns");this.qa=a.Ab.u.xF.call(this,"rowHeader")};a.b.g("FlattenedTreeDataGridDataSource.prototype.Init",{Init:a.Ab.prototype.Init});a.Ab.prototype.getCountPrecision=function(a){return"row"===a?"estimate":"actual"};a.b.g("FlattenedTreeDataGridDataSource.prototype.getCountPrecision",{getCountPrecision:a.Ab.prototype.getCountPrecision});a.Ab.prototype.getCount=function(a){return"row"===a?-1:"column"===a?this.Tf.length:0};a.b.g("FlattenedTreeDataGridDataSource.prototype.getCount",
{getCount:a.Ab.prototype.getCount});a.Ab.prototype.fetchHeaders=function(g,b,c){var d,e;d=g.axis;if("column"===d)d=g.start+g.count,d>this.getCount("column")&&(d=this.getCount("column")-g.start),e=new a.Hh(g.start,d,this.Tf);else if("row"===d&&null!=this.qa){this.Ip={range:g,callbacks:b,callbackObjects:c};return}null!=b&&null!=b.success&&(null==c&&(c={}),b.success.call(c.success,e,g,null))};a.b.g("FlattenedTreeDataGridDataSource.prototype.fetchHeaders",{fetchHeaders:a.Ab.prototype.fetchHeaders});a.Ab.prototype.fetchCells=
function(g,b,c){var d,e,f,h;for(d=0;d<g.length;d++)if(e=g[d],"row"==e.axis){f=e.start;h=e.count;break}a.Ab.u.tp.call(this,{start:f,count:h},{success:function(a){this.wU(a,g,b,c,0)}.bind(this),error:function(a){this.Vwa(a,{start:f,count:h},b,c)}.bind(this)})};a.b.g("FlattenedTreeDataGridDataSource.prototype.fetchCells",{fetchCells:a.Ab.prototype.fetchCells});a.Ab.prototype.keys=function(g){var b,c;b=g.row;c=g.column;return new Promise(function(d){b>a.Ab.u.ZHa.call(this).end||c>this.Tf.length?d(null):
d({row:a.Ab.u.getKey.call(this,b),column:this.Tf[c]})}.bind(this))};a.b.g("FlattenedTreeDataGridDataSource.prototype.keys",{keys:a.Ab.prototype.keys});a.Ab.prototype.indexes=function(g){var b,c,d,e,f;d=g.row;e=g.column;return new Promise(function(g){b=a.Ab.u.dl.call(this,d);for(f=0;f<this.Tf.length;f++)if(this.Tf[f]===e){c=f;break}0<=b||0<=c?g({row:b,column:c}):g(null)}.bind(this))};a.b.g("FlattenedTreeDataGridDataSource.prototype.indexes",{indexes:a.Ab.prototype.indexes});a.Ab.prototype.sort=function(g,
b,c){return a.Ab.u.getWrappedDataSource.call(this).sort(g,{success:function(){this.HU(b,c)}.bind(this),error:b.error})};a.b.g("FlattenedTreeDataGridDataSource.prototype.sort",{sort:a.Ab.prototype.sort});a.Ab.prototype.HU=function(a,b){this.refresh();a.success&&(null==b&&(b={}),a.success.call(b.success))};a.Ab.prototype.move=function(g,b,c,d){a.Ab.u.getWrappedDataSource.call(this).move(g,b,c,d)};a.b.g("FlattenedTreeDataGridDataSource.prototype.move",{move:a.Ab.prototype.move});a.Ab.prototype.getCapability=
function(g){return"default"===a.Ab.u.getWrappedDataSource.call(this).getCapability(g)?"column":"none"};a.b.g("FlattenedTreeDataGridDataSource.prototype.getCapability",{getCapability:a.Ab.prototype.getCapability});a.Ab.prototype.EF=function(g,b){a.Ab.u.EF.call(this,g,b)};a.Ab.prototype.wU=function(g,b,c,d){var e,f,h,k,l,m;for(e=0;e<b.length;e++)f=b[e],"row"==f.axis?(h=f.start,k=f.count):"column"==f.axis&&(l=f.start,m=f.count,l+m>this.getCount("column")&&(m=this.getCount("column")-l));this.Ip&&(e=this.Ip.range,
e.start==h&&e.count==k&&(this.CU(g,e,this.Ip.callbacks,this.Ip.callbackObjects),this.Ip=null));g=new a.ul(h,h+k,l,l+m,g,this.Tf);c.success&&(null==d&&(d={}),c.success.call(d.success,g,b))};a.Ab.prototype.Vwa=function(a,b,c,d){var e;this.Ip&&(e=this.Ip.range,e.start==b.start&&e.count==b.count&&(b=this.Ip.callbacks,e=this.Ip.callbackObjects,b.error&&(null==e&&(e={}),b.error.call(e.error,a))),this.Ip=null);c.error&&(null==d&&(d={}),c.success.call(d.error,a))};a.Ab.prototype.CU=function(g,b,c,d){g=new a.Hh(b.start,
b.start+b.count,this.Tf,g,this.qa);c.success&&(null==d&&(d={}),c.success.call(d.success,g,b,null))};a.Ab.prototype.jN=function(g,b,c){var d,e,f,h;d=null;this.qa&&(d=new a.Hh(g,g+c.getCount(),this.Tf,c,this.qa));b=new a.ul(g,g+c.getCount(),0,this.Tf.length,c,this.Tf);f=[];h=[];for(e=0;e<c.getCount();e++)f.push({row:this.Oj(g+e).key}),h.push({row:g+e,column:-1});g={source:this,operation:"insert"};g.result=b;d&&(g.header=d);g.keys=f;g.indexes=h;a.Ab.u.handleEvent.call(this,"change",g)};a.Ab.prototype.kO=
function(g){var b,c,d;b=[];d=[];for(c=0;c<g.length;c++)b.push({row:g[c].key}),d.push({row:g[c].index,column:-1});g={source:this,operation:"delete"};g.keys=b;g.indexes=d;a.Ab.u.handleEvent.call(this,"change",g)};a.Ab.prototype.iZ=function(g,b){b.success.call(null,new a.dh(null,g.start))}});